﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using HandlingInput;
using GameCore;


namespace GameObject
{
    public class House: StaticObject
    {
        bool enter_flag = false;

        Point gate;

        public Point Gate
        {
            get { return gate; }
            set { gate = value; }
        }

        public virtual event GetEvent Enter;
        public virtual event GetEvent Hover;
        public virtual event GetEvent Normal;

        public void SetAction(List<ActionButton> action)
        {
            this.List_Action = action;
        }
        public override bool CanActack()
        {
            return true;
        }

        public override bool Init(int _numberSprite, string[] strResource, string Name)
        {
            Enter += new GetEvent(House_Enter);

            return base.Init(_numberSprite, strResource, Name);
        }

        void House_Enter(VisibleGameEntity sender, GameCore.GameState gs)
        {
         //   MessageSender.GetEvent handle = (MessageSender.GetEvent)MessageSender.SetActionButton;
         //   if (handle != null)
        //        handle(this, List_Action);
            MessageSender.excute( this, List_Action);
        }

        public override void Update(GameTime gameTime, float x, float y, int w, int h)
        {
            this.X = x;
            this.Y = y;
            this.Width = w;
            this.Height = h;

            EventHandle.Update();

            _lsprite.Clear();
            _lsprite.Add(new Vector2(0, 0));



                if (EventHandle.MouseLeftClick(new Rectangle((int)this.X, (int)this.Y, (int)this.Width, (int)this.Height)))
                {

                    GetEvent handle = Enter;

                    if (handle != null)
                        handle(this, GlobalDefine.now_gamestate);
                }
                else
                    if (EventHandle.MouseOver(new Rectangle((int)this.X, (int)this.Y, (int)this.Width, (int)this.Height)))
                    {

                        GetEvent handle = Hover;

                        if (handle != null)
                            handle(this, GlobalDefine.now_gamestate);
                    }
                    else
                    {

                        GetEvent handle = Normal;

                        if (handle != null)
                            handle(this, GlobalDefine.now_gamestate);
                    }
                
   


            base.Update(gameTime, x, y, w, h);
        }
        public override VisibleGameObject Clone()
        {
            VisibleGameObject newObj = new House();
            newObj._lsprite = this._lsprite;
            newObj._nsprite = this._nsprite;
            newObj._sprite = new Sprite[_nsprite];
            for (int i = 0; i < _nsprite; i++)
            {
                newObj._sprite[i] = this._sprite[i].Clone();
            }
            newObj.X = this.X;
            newObj.Y = this.Y;
            newObj.Height = this.Height;
            newObj.Width = this.Width;

            ((House)newObj).Name = Name;
            ((House)newObj).Object_iD = Object_iD;
            for (int i = 0; i < List_Action.Count; i++)
            {
                ((House)newObj).List_Action.Add((ActionButton)List_Action[i].Clone());
            }
            ((House)newObj).Enter = this.Enter;
                
            
            return newObj;

        }

    }
}
